package com.qj.yantaishan.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qj.yantaishan.common.core.domain.R;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.ProductSku;
import com.qj.yantaishan.service.IProductSkuService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 商品库存Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/ProductSku")
public class ProductSkuController extends BaseController
{
    private String prefix = "yantaishan/ProductSku";

    @Autowired
    private IProductSkuService productSkuService;

    @RequiresPermissions("yantaishan:sku:view")
    @GetMapping()
    public String sku()
    {
        return prefix + "/sku";
    }

    /**
     * 查询商品库存列表
     */
    @RequiresPermissions("yantaishan:sku:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductSku productSku)
    {
        startPage();
        List<ProductSku> list = productSkuService.selectProductSkuList(productSku);
        return getDataTable(list);
    }
    /**
     * 商品库存
     */
    @GetMapping("list")
    public R page(Integer current,Integer size,String keyword,String orderBy,String sort){
        Page<ProductSku> productSkuPage=new Page<>(current,size);



        return R.ok();
    }


    /**
     * 导出商品库存列表
     */
    @RequiresPermissions("yantaishan:sku:export")
    @Log(title = "商品库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductSku productSku)
    {
        List<ProductSku> list = productSkuService.selectProductSkuList(productSku);
        ExcelUtil<ProductSku> util = new ExcelUtil<ProductSku>(ProductSku.class);
        return util.exportExcel(list, "商品库存数据");
    }

    /**
     * 新增商品库存
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品库存
     */
    @RequiresPermissions("yantaishan:sku:add")
    @Log(title = "商品库存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductSku productSku)
    {
        return toAjax(productSkuService.insertProductSku(productSku));
    }

    /**
     * 修改商品库存
     */
    @RequiresPermissions("yantaishan:sku:edit")
    @GetMapping("/edit/{skuId}")
    public String edit(@PathVariable("skuId") Integer skuId, ModelMap mmap)
    {
        ProductSku productSku = productSkuService.selectProductSkuBySkuId(skuId);
        mmap.put("productSku", productSku);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品库存
     */
    @RequiresPermissions("yantaishan:sku:edit")
    @Log(title = "商品库存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductSku productSku)
    {
        return toAjax(productSkuService.updateProductSku(productSku));
    }

    /**
     * 删除商品库存
     */
    @RequiresPermissions("yantaishan:sku:remove")
    @Log(title = "商品库存", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productSkuService.deleteProductSkuBySkuIds(ids));
    }
}
